-
Notifications
You must be signed in to change notification settings - Fork 777
SOLR-17942: Raising configurable RAM per thread hard limit using VarHandle #3741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
punAhuja
wants to merge
10
commits into
apache:main
Choose a base branch
from
SearchScale:puneet/SOLR-17942-raising-ramPerThreadHardLimit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
SOLR-17942: Raising configurable RAM per thread hard limit using VarHandle #3741
punAhuja
wants to merge
10
commits into
apache:main
from
SearchScale:puneet/SOLR-17942-raising-ramPerThreadHardLimit
+47
−2
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dsmiley
reviewed
Oct 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Java 9 and beyond, I suggest VarHandle API instead:
// A lookup object that can see the private members of this class.
MethodHandles.Lookup lookup = MethodHandles.lookup();
VarHandle fieldHandle = null;
Class<?> currentClass = config.getClass();
// Loop to find the field in the class hierarchy
while (currentClass != null && fieldHandle == null) {
try {
// Get a special lookup that can access private members of the target class.
// This requires `--add-opens` if the target is in another module.
MethodHandles.Lookup privateLookup = MethodHandles.privateLookupIn(currentClass, lookup);
// Find a handle for the field by name and type.
fieldHandle = privateLookup.findVarHandle(currentClass, "perThreadHardLimitMB", int.class);
} catch (IllegalAccessException | NoSuchFieldException e) {
// Field not in this class, try the superclass.
currentClass = currentClass.getSuperclass();
}
}
try {
if (fieldHandle != null) {
// Set the value using the handle.
fieldHandle.set(config, limitMB);
log.info("Set perThreadHardLimitMB to {} MB via VarHandle", limitMB);
} else {
log.error("Could not find VarHandle for perThreadHardLimitMB field");
}
} catch (Throwable t) { // VarHandle.set can throw Throwable
log.error("Failed to set per-thread RAM limit via VarHandle", t);
}…hub.com:SearchScale/solr into puneet/SOLR-17942-raising-ramPerThreadHardLimit
Thanks, I have updated the pull request to use VarHandle instead of reflection. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://issues.apache.org/jira/browse/SOLR-17942
Description
The parameter ramPerThreadHardLimitMB cannot be configured more than 2GB in Lucene, as a consequence a single thread cannot write segments larger than 2GB.
Refer: https://lucene.apache.org/core/9_9_0/core/org/apache/lucene/index/IndexWriterConfig.html#setRAMPerThreadHardLimitMB(int)
Solution
This PR makes this parameter configurable above the 2GB limit, so that each thread can write a bigger segment. I use VarHandle to bypass this hard-coded limit in Lucene.
When ramPerThreadHardLimitMB is configured with a value more than 2GB, setPerThreadRAMLimitViaVarHandle is called, bypassing the limit
Tests
Checklist
Please review the following and check all that apply:
mainbranch../gradlew check.